﻿#ifndef LOGSAVER_H
#define LOGSAVER_H

#include <qobject.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qthread.h>

class LogSaver1;
class LogSaver :  public QObject
{
  Q_OBJECT
public:
  enum LogFlag
  {
    Debug = 0x01,
    Information = 0x02,
    Warning = 0x04,
    Critical = 0x08
  };
private:
  int logLevel = 0;
  QString logFilePath = "NBIOT_Log1";
  QString logFileSuffix = ".log";
#if defined (WIN64) || defined (WIN32)
  QString newLine = "\r\n";
#endif
#if defined (linux)
  QString newLine = "\n";
#endif
  QString QString_debug = "(Debug)";
  QString QString_information = "(Information)";
  QString QString_warning = "(Warning)";
  QString QString_critical = "(Critical)";
  QFile* qfile=Q_NULLPTR;
  static LogSaver* logSaver;
private:
  LogSaver(QObject* parent = Q_NULLPTR);
  LogSaver& operator=(LogSaver&);
  LogSaver(const LogSaver&);
public:
  virtual ~LogSaver();
signals:
  void signal_writeLogToFile(QString msg,QFile* file);
public:
  static LogSaver* getLogSaver();
  void saveLog(QString msg, uchar logFlag=Information);
  void enableLogLevel(uchar logFlag);//log level control
  void disableLogLevel(uchar logFlag);//log level control
  QString getQStringOfLogFlag(uchar logFlag);
public://geter and seter
  int getLogLevel();
  QString getLogFilePath();
  void setLogFilePath(QString filePath);
};
#endif

#ifndef LOGSAVER1_H
#define LOGSAVER1_H
class LogSaver1:public QObject
{
  Q_OBJECT
private:
  friend class  LogSaver;
private:
  explicit LogSaver1();
  virtual ~LogSaver1();
private slots:
  void slot_writeLogToFile(QString msg,QFile* file);
};
#endif
